package zuoye28.zuoye2;

import java.util.Scanner;

public class School {
    //计算平均课时:输入总课时和课程数,计算平均课时.要求捕捉输入和除法错误;如果总课时少于100,抛出课时太少的错误
    public static void main(String[] args) throws Exception {
        System.out.println("请输入总课时：");
        Scanner scanner1 = new Scanner(System.in);
        System.out.println("请输入课程数：");
        Scanner scanner2 = new Scanner(System.in);
        if (!scanner1.hasNextInt() || !scanner2.hasNextInt()) { //hasNextInt()检查输入流中是否还有下一个int类型的值
            throw new Exception("输入的不是数字！");
        }
        int course = scanner1.nextInt();
        int count = scanner2.nextInt();

        if (course < 100) {
            throw new Exception("课时太少!");
        }
        if(count==0){
            throw new Exception("课程数不能等于0");  //t替换默认java的报错异常
        }
        try {
            double result = course / count;
            System.out.println("平均课时是：" + result);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}
